package label

import (
	"context"

	"label/internal/svc"
	"label/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListLogic {
	return &ListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ListLogic) List(req *types.Request) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	list, err := l.svcCtx.LabelModel.List(l.ctx)

	var labels []types.LabelResp

	for _, label := range list {
		l := types.LabelResp{
			Id:       label.Id,
			Name:     label.Name,
			Type:     label.Type,
			Url:      label.Url.String,
			Icon:     label.Icon.String,
			ParentId: label.ParentId.Int64,
		}
		labels = append(labels, l)
	}
	resp1 := &types.Response{
		Data: labels,
	}
	return resp1, nil
}
